//
//  CellForType.m
//  喜马拉雅FM
//
//  Created by dllo on 16/3/2.
//  Copyright © 2016年 lanou.com. All rights reserved.
//

#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height

#import "CellForType.h"
#import "ModelForTypeOfListOfDetail.h"
#import "CellForTypeOfDetail.h"
#import "ModelForTypeOfDetail.h"
#import "SecendViewController.h"

#import "ModelForListen.h"

@interface CellForType ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arrForList;


@end

@implementation CellForType



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
       
    
        self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0, [UIScreen mainScreen].bounds.size.width, 300) style:UITableViewStylePlain];
        [self.contentView addSubview:self.tableView];
        [self.tableView release];
        
        // 关闭内层tableView的上下滑动.
        self.tableView.scrollEnabled = NO;
        
        self.tableView.dataSource = self;
        self.tableView.delegate = self;
        
        [self.tableView registerClass:[CellForTypeOfDetail class] forCellReuseIdentifier:@"poolForCellForTypeOfDetail"];
    }
    return self;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 

    return self.arrForList.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

 
    ModelForListen *model = [self.arrForList objectAtIndex:indexPath.row];
    CellForTypeOfDetail *cell = [tableView dequeueReusableCellWithIdentifier:@"poolForCellForTypeOfDetail"];
    [cell passModelTypeForListDetail:model];
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 100;
}


- (void)passModelForTypeOfDetail:(ModelForTypeOfDetail *)model{
    
    // 初始化数组.
    self.arrForList = [NSMutableArray array];
    
    NSArray *tempArr = model.arrForListDetail;
    
    for (ModelForTypeOfListOfDetail *modelForListDetail in tempArr) {
        [self.arrForList addObject:modelForListDetail];
    }
    
    [self.tableView reloadData];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ModelForListen *model = [self.arrForList objectAtIndex:indexPath.row];
  
    // 获取该视图层最下边的VC.
    id object = [self nextResponder];
    while (![object isKindOfClass:[UIViewController class]] &&
           object != nil) {
        object = [object nextResponder];
    }
    UIViewController *vc = (UIViewController*)object;
    
    SecendViewController *secend = [[SecendViewController alloc]init];
    secend.stringForAlbumID = model.albumId;
    secend.modelForListen = model;
    
    [vc.navigationController pushViewController:secend animated:YES];
    

}

- (void)awakeFromNib {
   
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
